package Lee_code;

import java.util.Arrays;

public class Lee_1365_dp {
    public int[] smallerNumbersThanCurrent(int[] nums) {

        int max_value = Arrays.stream(nums).max().getAsInt();
        int[] dp = new int[nums.length];

        for(int i = 0; i < nums.length; i++){
            for(int j = max_value; j>= nums[i]; j--)
            {
                dp[j] = Math.max(dp[j], dp[j-nums[i]+1]);
            }
        }

        int[] res = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            res[i] = dp[res[i]];
        }
        return res;
    }
}
